package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Person p = new Person("李四");
        System.out.println(p);

        Class cls = Class.forName("reflect.Person");

        //Person(string)
        Constructor c = cls.getConstructor(String.class);
        Object obj = c.newInstance("王五");
        System.out.println(obj);

        //Person(string,int)
        Constructor c2 = cls.getConstructor(String.class, int.class);
        //new Person("赵六”33);
        Object obj2 = c2.newInstance("赵六", 33);
        System.out.println(obj2);
    }
}
